import java.io.IOException;
import java.net.Socket;

/**
 * 支持多线程连接的服务器
 */
public class TCPThreadServer extends TCPEchoServer{
    public TCPThreadServer(int port) throws IOException {
        super(port);
    }

    @Override
    public void start() throws IOException {
        System.out.println("TCPThread服务器已启动...");
        //循环创建多线程连接客户端
        while (true) {
            //等待客户端连接
            Socket clientSocket = socket.accept();
            //为每一个客户端都创建一个线程
            Thread thread = new Thread(() -> {
                processConnections(clientSocket);
            });
            //启动线程，调用CPU资源
            thread.start();
        }
    }

    public static void main(String[] args) throws IOException {
        TCPThreadServer tcpThreadServer = new TCPThreadServer(6666);
        tcpThreadServer.start();
    }
}
